<template>
	<view style="padding: 30rpx;">
		<button @click="onSetTimeCall()">单次定时器setTimeout</button>
		<button @click="onSetTimeCallxy(userName,pwd)">带参数setTimeout</button>
		<button @click="onTimeoutclear()" type="warn">取消定时器</button>
		<button @click="onIterval()" type="primary">周期打印</button>
		<button @click="onClearIter()" type="primary">取消周期打印</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userName:'xxx',
				pwd:'666',
				timeoutid:null,
				cout:0,
				interalID:null
			}
		},
		methods: {
			onSetTimeCall(){
				console.log("onSetTimeCall-->");
				// setTimeout(callback,ms,any[])
				this.timeoutid=setTimeout(()=>{
					// 延时2000毫秒之后要执行的代码
					console.log("我延时2秒后才会打印");
				},2000)
			},
			onSetTimeCallxy(name,pwd){
				console.log("onSetTimeCallxy()--> name" + name + "pwd"+pwd);
				// console.log("onSetTimeCallxy--> name:" +this.userName+",pwd" + this.pwd);
				setTimeout((x,y)=>{
					console.log("我可以传> x:"+x+",y" +y);
				},2000,name,pwd)
			},
			onTimeoutclear(){
				console.log("onTimeoutclear----->定时器被我取消了："+ this.timeoutid);
				clearTimeout(this.timeoutid);
			},
			onIterval(){
				setInterval(()=>{
					this.cout++;
					console.log("周期打印 count:",this.count);
				},10000)
			},
			onClearIter(){
				console.log("onClearIter:", this.interalID);
				clearInterval(this.interalID)
			}
		}
	}
</script>

<style>
button{
	margin: 30rpx;
}
</style>
